package cn.snoworld.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.snoworld.service.LinkService;
import cn.snoworld.dto.CommonResult;
import cn.snoworld.entity.Link;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "快捷访问链接接口")
@RestController
@RequestMapping("/blog/link")
public class LinkController {
    @Autowired
    private LinkService linkService;

    @GetMapping
    @ApiOperation("获取所有link")
    public CommonResult getAll() {
        return CommonResult.OK(linkService.list());
    }

    @ApiOperation("根据id获取link")
    @GetMapping("{id}")
    public CommonResult getOneById(@PathVariable Integer id) {
        return CommonResult.OK(linkService.getById(id));
    }

    @ApiOperation("新增一个link")
    @PostMapping
    public CommonResult addOne(@RequestBody Link link) {
        linkService.save(link);
        return CommonResult.OK();
    }

    @PutMapping
    @ApiOperation("修改一个link")
    public CommonResult modifyOneById(@RequestBody Link link) {
        linkService.updateById(link);
        return CommonResult.OK();
    }

    @DeleteMapping("{id}")
    @ApiOperation("根据id删除link")
    public CommonResult removeOneById(@PathVariable Integer id) {
        linkService.removeById(id);
        return CommonResult.OK();
    }
}
